import urllib, csv

#tickers=['NASDAQ:GOOG', 'NASDAQ:YHOO', 'NASDAQ:MSFT', 'NYSE:UBS', 'NYSE:C']
tickers=['GOOG', 'YHOO', 'MSFT', 'ABN', 'SNP', 'GS', 'UBS', 'RBS', 'AAPL',
         'AXP', 'CCE', 'DIS', 'FDX', 'GM', 'MS', 'RTN', 'SBUX', 'SI',
         'BP','ITY']

closeval={}

for ticker in tickers:

    closeval[ticker]=[]
    #f=urllib.urlopen('http://finance.google.com/finance/historical?q=' +
    #                 ticker + '&output=csv')

    f=urllib.urlopen('http://ichart.finance.yahoo.com/table.csv?s=' + ticker +'&d=4&e=30&f=2008&g=d&a=1&b=1&c=2007&ignore=.csv')
    
    f.readline()
    for row in csv.reader(f):
        closeval[ticker].append(row[6])

f=open("data2.csv", "wb")
writer = csv.writer(f)
for values in closeval.values():
    print len(values)
    writer.writerow(values[0:120])

f.close()
